'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview boss
 * @author sundbcn@gmail.com (sun debing)
 */

var dataApi = require('../dataApi');
var attrFromAtkType = require('./attrFromAtkType');
var weaknessAttr = require('./weaknessAttr');
var resistanceAttr = require('./resistanceAttr');
var constantUtil = require('../../util/constantUtil');
var unionBossConf = require('../../config/unionBossConf');

/**
 * 获取联盟BOSS信息
 * @param  {[type]} soldier_type [description]
 * @param  {[type]} soldier_lv   [description]
 * @return {[type]}              [description]
 */
exports.getData = function (boss_id) {
    var union_boss_conf = dataApi.union_boss.findById(boss_id);
    if (!union_boss_conf) {
        console.error('union boss_id not found:' + boss_id);
        return {};
    }
    var atk_type_attr = attrFromAtkType.getAttr(
        union_boss_conf.atk_type,
        union_boss_conf.atk
    );

    var boss_info = {
        boss_type: boss_id,
        attr: {
            min_atk: atk_type_attr.min_atk * (100 - constantUtil.value('boss_atk_region')) / 100 || 0,
            max_atk: atk_type_attr.max_atk * (100 + constantUtil.value('boss_atk_region')) / 100 || 0,
            fire_damage: atk_type_attr.fire_damage,
            ice_damage: atk_type_attr.ice_damage,
            light_damage: atk_type_attr.light_damage,
            city_damage: atk_type_attr.city_damage,
            physical_def: 0,
            fire_def: 0,
            ice_def: 0,
            light_def: 0,
            hp: union_boss_conf.hp,
            hit: union_boss_conf.hit,
            dodge: union_boss_conf.dodge,
            crit: union_boss_conf.crit,
            uncrit: union_boss_conf.uncrit,
            crit_addition: constantUtil.value('crit_addition'),
            atk_interval: union_boss_conf.atk_interval,
            atk_range: union_boss_conf.atk_range,
            warn_range: union_boss_conf.warn_range,
            speed: union_boss_conf.speed,
            atk_kind: union_boss_conf.atk_kind,
            weakness_list: weaknessAttr.getAttr(union_boss_conf.weakness_type),
            resistance_list: resistanceAttr.getAttr(union_boss_conf.resistance_type)
        },
        skill_list: _getSkillAttr(union_boss_conf)
    };

    var boss_list = [boss_info];
    return {
        boss_list: boss_list
    };
};

/**
 * 获取技能列表
 * @param  {[type]} boss_id [description]
 * @return {[type]}         [description]
 */
var _getSkillAttr = function (union_boss_conf) {
    var skill_list = [];
    for (var num = 1; num <= 5; num++) {
        var key = 'skill_id' + num;
        if (!!union_boss_conf[key]) {
            skill_list.push(union_boss_conf[key]);
        }
    }
    return skill_list;
};
